<?php
namespace app\service;
// +----------------------------------------------------------------------
// | bbcThink
// +----------------------------------------------------------------------
// | Copyright (c) 2025 http://bbcweb.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: bbcweb <22745529@qq.com>
// +----------------------------------------------------------------------
use think\facade\Db;

//供应商
class ShopService
{
    public static function paginate($param)
    {
        $field=isset($param['field'])?$param['field']:'*';
        $sort=isset($param['sort'])?$param['sort']:'id desc';
        $pagesize=isset($param['pagesize'])?$param['pagesize']:10;
        $datalist=Db::name('shop')->where(['country_id'=>cache('lang_id')])->where($param['where'])->field($field)->order($sort)->paginate(['list_rows'=>$pagesize,'query'=>$param['query']]);
        $list=[];
        foreach ($datalist->items() as $v)
        {
             $list[]=self::handleData($v);
        }
        return ['list'=>$list,'total'=>$datalist->total(),'pager'=>$datalist->render()];
    }
    public static function handleData($v)
    {
        return $v;
    }
    public static function info($param)
    {
        if(empty($param['id']))
        {
            return null;
        }
        $info=cache('shop_info_'.$param['id']);
        if(empty($info))
        {
            $info=Db::name('shop')->where(['id'=>$param['id']])->find();
            cache('shop_info_'.$param['id'],$info);
        }
        return $info;
    }
    public static function somelist($param=null)
    {
        $where=isset($param['where'])?$param['where']:[];
        
        $datalist=Db::name('shop')->where($where)->where(['country_id'=>cache('lang_id')])->select()->toarray();
        return $datalist;
    }
    
}